package net.amsoft.iservice.icontact.util;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.ResourceBundle;

import net.amsoft.iservice.util.IServiceConstants;

import org.apache.log4j.Logger;

public class IContactConstants {

	private static final Logger oLog = Logger
			.getLogger(IContactConstants.class);
	private static ResourceBundle bundle = ResourceBundle
			.getBundle("icontactResources");

	public static final int PENDING = 0;
	public static final int ACTIVE = 1;
	public static final int BANNED = 2;
	public static final int INACTIVE = 3;

	public static final int VER_TYPE_NONE = 0;
	public static final int VER_TYPE_INAME = 1;
	public static final int VER_TYPE_EMAIL = 2;
	public static final int DEF_VER_TYPE = 2;

	// forwards
	public static final String FWD_CHKLOGIN = "CheckLogin";
	public static final String FWD_SUCCESS = "success";
	public static final String FWD_FAILURE = "failure";
	public static final String FWD_MSG = "msg";

	// errors
	public static final String ERR_INVALID = "err.invalid";
	public static final String ERR_REQUIRED = "err.required";
	public static final String ERR_GLOBAL_LOGOUT_NOT_DONE = "err.global.logout.not.done";
	public static final String ERR_UKNOWN_GLOBAL_SESSION = "err.unknown.global.session";
	public static final String ERR_AUTHN_FAILED = "err.authn.failed";
	public static final String ERR_PAGE_NOT_EXIST = "err.page.not.exist";
	public static final String ERR_INAME_UNRESOLVED = "iname.not.resolved";

	// configuration field constants
	public static final String NAME = "label.name";
	public static final String EMAIL_ADDRESS = "label.email";
	public static final String MESSAGE = "label.msg";
	public static final String DEFAULT_SENDER_NAME = "default.sender.name";

	// messages
	public static final String MSG_LOGIN_SUCCESS = "msg.login.success";
	public static final String MSG_LOGOUT_SUCCESS = "msg.logout.success";
	public static final String MSG_REQ_SENT = "msg.req.sent";
	public static final String MSG_VER_EMAIL_SENT = "msg.ver.email.sent";
	public static final String MSG_REQ_DELETED = "msg.req.deleted";
	public static final String MSG_REQ_NOT_DELETED = "msg.req.not.deleted";
	public static final String MSG_CONF_SAVED = "msg.conf.saved";
	public static final String MSG_CPAGE_DEACTIVATED = "msg.conf.deactivated";
	public static final String MSG_VER_EMAIL = "msg.ver.email";
	public static final String MSG_DEF_VER_EMAIL_SUB = "msg.def.ver.email.sub";
	public static final String MSG_DEF_NOT_EMAIL_SUB = "msg.def.not.email.sub";
	public static final String MSG_DEF_NOT_EMAIL_MSG = "msg.not.email";
	public static final String MSG_DEF_REPLY_EMAIL_MSG = "msg.def.reply.email";
	public static final String MSG_DEF_FROM_EMAIL_ADDR = IServiceConstants.ISERVICE_BUNDLE
			.getString(IServiceConstants.EMAIL_FROM);

	public static Hashtable<String, String> oIBrokerTable = new Hashtable<String, String>();

	public static final String SESSION_LOGIN_OBJ = "LoginData";
	public static final String SESSION_IBROKER_OBJ = "IBrokerData";
	public static final String SESSION_CPAGE = "ContactPage";
	public static final String SESSION_CONTACT_REQ = "ContactRequest";
	public static final String SESSION_REQ_DATA = "RequestData";
	public static final String SESSION_SYN = "synonym";
	public static final String SESSION_REF = "reference";
	public static final String SESSION_CONFIG_FRM = "ConfigForm";
	public static final String SESSION_REQ_COUNT = "TotalReq";
	public static final String SESSION_REQ_RES = "reqResList";

	public static final String REQ_MSG_LIST = "msgList";
	public static final String REQ_REPLY_LIST = "replyList";
	public static final String REQ_CUR_MSG_PAGE = "m";
	public static final String REQ_CUR_REPLY_PAGE = "r";
	public static final String REQ_EXP_ROW_ID = "expRow";
	public static final String REQ_LAST_TYPE = "lastType";
	public static final String REQ_GRP_SYNONYMS = "groupList";
	public static final String REQ_PTR_STEP = "step";
	public static final String REQ_PTR_STEP_SAVE = "save";
	public static final String REQ_PTR_STEP_CANCEL = "cancel";
	public static final String REQ_PTR_SYN = "xri";
	public static final String REQ_PTR_HASH = "ref";

	public static final String TYPE_ACTIVATED_SEPARATE = "activated";
	public static final String TYPE_GROUP_ACTIVATED = "groupActivated";
	public static final String TYPE_DEACTIVATED = "deactivated";
	public static final String TYPE_ACTIVATE_EDIT = "edit";

	public static final String VERIFICATION_ACTION = "/icontact/Verify";
	public static final String CONTACT_ACTION = "/icontact/Contact";

	public static final int MAX_REPLIES_COUNT = 10;
	public static final int MAX_MSGS_COUNT = 10;

    public static final String LOAD_BALANCER_IP = IServiceConstants.LOADBALANCER_IP;
    
	// Requested Authentication Contexts and Comparison type
	public static final String RAC_NAMES_LIST = bundle
			.getString("rac.names.list");
	public static final String RAC_COMPARISON_TYPE = bundle
			.getString("rac.comparison.type");

	public static final void initializeIbrokerData() {
		if (oIBrokerTable == null || oIBrokerTable.size() == 0) {
			ResourceBundle oBundle = ResourceBundle.getBundle("ibrokers");
			Enumeration oBundleKeys = oBundle.getKeys();
			while (oBundleKeys.hasMoreElements()) {
				String sIBname = (String) oBundleKeys.nextElement();
				oIBrokerTable.put(sIBname, oBundle.getString(sIBname));
			}
		}
	}

	public static final String getSPXri(String ibrokerName) {
		if (oIBrokerTable == null || !oIBrokerTable.containsKey(ibrokerName))
			initializeIbrokerData();

		String sXRI = (String) oIBrokerTable.get(ibrokerName);
		oLog.debug("getSPXri(): IB=" + ibrokerName + ", XRI=" + sXRI);
		return sXRI;
	}
}
